package cn.com.guage.dtm.verify.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.core.page.TableDataInfo;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.metadata.domain.MdField;
import cn.com.guage.dtm.metadata.domain.MdModule;
import cn.com.guage.dtm.metadata.domain.MdSys;
import cn.com.guage.dtm.metadata.domain.MdTable;
import cn.com.guage.dtm.metadata.service.IMdFieldService;
import cn.com.guage.dtm.metadata.service.IMdModuleService;
import cn.com.guage.dtm.metadata.service.IMdSysService;
import cn.com.guage.dtm.metadata.service.IMdTableService;
import cn.com.guage.dtm.verify.domain.VerifyFieldRuleManage;
import cn.com.guage.dtm.verify.service.IVerifyFieldRuleManageService;

/**
 * 字段检核规则Controller
 * 
 * @author yangdechao
 * @date 2021-06-24
 */
@Controller
@RequestMapping("/verify/rule")
public class VerifyFieldRuleManageController extends BaseController
{
    private String prefix = "verify/rule";

    @Autowired
    private IVerifyFieldRuleManageService verifyFieldRuleManageService;
    @Autowired
    private IMdTableService mdTableService;
    @Autowired
    private IMdSysService mdSysService;
    
    @Autowired
    private IMdModuleService mdModuleService;
    @Autowired
    private IMdFieldService mdFieldService;
    
    @RequiresPermissions("verify:rule:view")
    @GetMapping()
    public String rule()
    {
        return prefix + "/rule";
    }

    /**
     * 查询字段检核规则列表
     */
    @RequiresPermissions("verify:rule:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VerifyFieldRuleManage verifyFieldRuleManage)
    {
        startPage();
        List<VerifyFieldRuleManage> list = verifyFieldRuleManageService.selectVerifyFieldRuleManageList(verifyFieldRuleManage);
        return getDataTable(list);
    }

    /**
     * 导出字段检核规则列表
     */
    @RequiresPermissions("verify:rule:export")
    @Log(title = "字段检核规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VerifyFieldRuleManage verifyFieldRuleManage)
    {
        List<VerifyFieldRuleManage> list = verifyFieldRuleManageService.selectVerifyFieldRuleManageList(verifyFieldRuleManage);
        ExcelUtil<VerifyFieldRuleManage> util = new ExcelUtil<VerifyFieldRuleManage>(VerifyFieldRuleManage.class);
        return util.exportExcel(list, "字段检核规则数据");
    }

    /**
     * 新增字段检核规则
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
    	 List<MdSys> mdSysList = mdSysService.selectMdSysList(null);
    	 modelMap.put("mdSysList", mdSysList);
        return prefix + "/add";
    }

    /**
     * 新增保存字段检核规则
     */
    @RequiresPermissions("verify:rule:add")
    @Log(title = "字段检核规则", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VerifyFieldRuleManage verifyFieldRuleManage)
    {
    	Integer result = verifyFieldRuleManageService.insertVerifyFieldRuleManage(verifyFieldRuleManage);
        return toAjax(result);
    }

    /**
     * 修改字段检核规则
     */
    @GetMapping("/edit/{checkRuleId}")
    public String edit(@PathVariable("checkRuleId") Long checkRuleId, ModelMap mmap)
    {
        VerifyFieldRuleManage verifyFieldRuleManage = verifyFieldRuleManageService.selectVerifyFieldRuleManageById(checkRuleId);
        mmap.put("verifyFieldRuleManage", verifyFieldRuleManage);
        return prefix + "/edit";
    }

    /**
     * 修改保存字段检核规则
     */
    @RequiresPermissions("verify:rule:edit")
    @Log(title = "字段检核规则", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VerifyFieldRuleManage verifyFieldRuleManage)
    {
        return toAjax(verifyFieldRuleManageService.updateVerifyFieldRuleManage(verifyFieldRuleManage));
    }

    /**
     * 删除字段检核规则
     */
    @RequiresPermissions("verify:rule:remove")
    @Log(title = "字段检核规则", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(verifyFieldRuleManageService.deleteVerifyFieldRuleManageByIds(ids));
    }
    
    /**
     * 加载系统代码表树
     */
    @GetMapping("/systemListData")
    @ResponseBody
    public List<VerifyFieldRuleManage> treeData()
    {
    	VerifyFieldRuleManage verifyFieldRuleManage = null;
        List<VerifyFieldRuleManage> list = verifyFieldRuleManageService.selectVerifyFieldRuleManageList(verifyFieldRuleManage);
        return list;
    }
    
    /**
     * 功能模块弹框
     */
    @GetMapping("/showMdModuleList/{sysId}")
    public String showModelList(@PathVariable("sysId") Long sysId, ModelMap mmap)
    {
		/*
		 * MdModule mdModule = new MdModule(); mdModule.setSysId(sysId); List<MdModule>
		 * result = mdModuleService.selectMdModuleList(mdModule);
		 */
        mmap.put("sysIdField", sysId);
        return prefix + "/md-module-list";
    }
    
    /**
     * 系统md弹框
     * 
     */
    @GetMapping("/showMdSysList")
    public String showMdSysList()
    {
        return prefix + "/md-sys-list";
    }
    
    @RequiresPermissions("verify:rule:showMdSysList")
    @PostMapping("/showMdSysList")
    @ResponseBody
    public TableDataInfo showMdSysList(MdSys mdSys)
    {
        startPage();
    	List<MdSys>  result = mdSysService.selectMdSysList(mdSys);
        return getDataTable(result);
    }
    /**
     * 功能模块弹框列表
     */
    @RequiresPermissions("verify:rule:showMdModuleList")
    @PostMapping("/showMdModuleList")
    @ResponseBody
    public TableDataInfo showModelList(MdModule mdModule)
    {
        startPage();
    	List<MdModule>  result = mdModuleService.selectMdModuleList(mdModule);
        return getDataTable(result);
    }
    
   
    
    /**
     * 表Md模块弹框
     * 
     */
    @GetMapping("/showMdTableList/{moduleId}")
    public String showMdtableList(@PathVariable("moduleId") Long moduleId, ModelMap mmap)
    {
        return prefix + "/md-table-list";
    }
    
    
    /**
     * 功能模块弹框列表
     */
    @RequiresPermissions("verify:rule:showMdTableList")
    @PostMapping("/showMdTableList")
    @ResponseBody
    public TableDataInfo showMdTableList(MdTable mdTable)
    {
        startPage();
    	List<MdTable>  result = mdTableService.selectMdTableList(mdTable);
        return getDataTable(result);
    }
    
    /**
     * md-field弹框列表
     */
    @GetMapping("/showMdFieldList/{tableCode}")
    public String showMdFieldList(@PathVariable("tableCode") Long tableCode, ModelMap mmap)
    {
        return prefix + "/md-field-list";
    }
    
    @RequiresPermissions("verify:rule:showMdFieldList")
    @PostMapping("/showMdFieldList")
    @ResponseBody
    public TableDataInfo showMdFieldList(MdField mdField)
    {
        startPage();
    	List<MdField>  result = mdFieldService.selectMdFieldList(mdField);
        return getDataTable(result);
    }
    
    @RequiresPermissions("mverify:rule:detail")
    @GetMapping("/detail/{checkRuleId}")
    public String detail(@PathVariable("checkRuleId") Long checkRuleId, ModelMap mmap)
    {
    	VerifyFieldRuleManage  verifyFieldRuleManage = verifyFieldRuleManageService.selectVerifyFieldRuleManageById(checkRuleId);
        mmap.put("verifyFieldRuleManage", verifyFieldRuleManage);
        return prefix + "/rule-detail";
    }
}
